import React, { Component } from 'react'
import { Table,Radio } from 'antd'

class ETable extends Component{
    onSelectChange =(selectedRowKeys, selectedRows)=>{
        this.props.updataSelectedItem(selectedRowKeys, selectedRows)
    }
    initTable =() =>{
        let row_selection = this.props.rowSelection;
        const rowSelection = {
            type: 'radio',
            onChange: this.onSelectChange
        }
        if( row_selection == false || row_selection == null ){
            row_selection = false
        }else if( row_selection == 'checkbox' ){
            rowSelection.type= 'checkbox'
        }else{
            rowSelection.type = 'radio'
        }
        return <Table
                    bordered
                    {...this.props}
                    rowSelection={row_selection ? rowSelection : null}
                />
    }
    render(){
        return (
            <div>
                {
                    this.initTable()           
                }
            </div>
        )
    }
}

export default ETable